#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class KWindowSystem;
class X11EventFilter;
class X11ClentEventFilter;

//带层级关系的子窗口
struct SWindowLevel{
    int                 iLevel;
    quint32             PID;
    unsigned long       parent;
    unsigned long       window;
    QString             sTitle;
    QRect               rect;
    QList<SWindowLevel> children;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    //显示所有窗口信息
    void showAllWindowInfo();

    //显示当前窗口信息
    void showActiveWindowInfo(WId wid);

    //获取SWindowLevel信息
    void getSWindowLevelInfo(SWindowLevel windowlevel);
public Q_SLOTS:
    //kwinsystem 定义的信号
    void onActiveWindowChanged(WId id);
    void onWindowAdded(WId id);
    void onWindowRemoved(WId id);

private slots:
    void on_m_ListenBtn_clicked();

protected:
    //初始化时获取所有窗口
    void getAllWindow(QList<WId>& arrWId);
    void getAllWindow(SWindowLevel &windowLevel);

    //根据窗口ID获取进程ID
    quint32 get_window_Pid(unsigned long win);

    //根据窗口ID获取窗口名
    QString get_window_name(unsigned long win);

    //根据窗口ID获取窗口位置大小
    QRect get_window_rect(unsigned long win);

    //根据窗口ID获取子窗口
    void get_window_Children(unsigned long win, QList<WId> &arrWId);

private:
    Ui::MainWindow      *ui;
    KWindowSystem       *m_windowSystem;
    X11EventFilter      *m_x11Event_Filter;
    X11ClentEventFilter *m_X11Client_Filter;
    unsigned long       m_ActiveWindow;
    QList<WId>          m_WId_List;
    quint32             m_ActivePid;
};

#endif // MAINWINDOW_H
